﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Script.UI.Component
{
    public class PillarModuleGroup : MonoBehaviour
    {
        public PillarModule currentGroup;
        public Dictionary<string, PillarModule> groups;
        public void Awake()
        {
            groups = new Dictionary<string, PillarModule>();
            var comps = transform.GetComponentsInChildren<PillarModule>(true);
            foreach (var pillarModule in comps)
            {
                if (pillarModule.gameObject.activeSelf)
                {
                    currentGroup = pillarModule;
                }
                groups.Add(pillarModule.data, pillarModule);
            }
        }

        public void Change(string key)
        {
            var group = groups[key];
            if (group == currentGroup)
            {
                return;
            }

            if (currentGroup)
            {
                currentGroup.gameObject.SetActive(false);
            }

            currentGroup = group;
            currentGroup.gameObject.SetActive(true);
        }
    }
}